package com.egg.ylt.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.egg.ylt.R;
import com.egg.ylt.pojo.InformationsEntity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * sichaoqi on 2018/12/18
 */
public class ADA_MessageRecyclerAdapter extends RecyclerView.Adapter<ADA_MessageRecyclerAdapter.MessageViewHolder> {


    private Context mContext;
    private LayoutInflater mInflater;
    private List<InformationsEntity.ListBean> mList;

    public ADA_MessageRecyclerAdapter(Context context) {
        this.mContext = context;
        mInflater = LayoutInflater.from(mContext);
        mList = new ArrayList<>();
    }

    /**
     * 设置数据
     * @param list
     */
    public void setDataList(List<InformationsEntity.ListBean> list) {
        if (mList != null) {
            mList.clear();
        }
        mList.addAll(list);
        notifyDataSetChanged();
    }

    /**
     * 添加数据
     * @param list
     */
    public void addDataList(List<InformationsEntity.ListBean> list) {
        mList.addAll(list);
        notifyDataSetChanged();
    }

    /**
     * 删除数据
     */
    public void clearDataList() {
    }

    @Override
    public MessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MessageViewHolder(mInflater.inflate(R.layout.item_message_recycler, parent, false));
    }

    @Override
    public void onBindViewHolder(MessageViewHolder holder, int position) {
        InformationsEntity.ListBean listBean = mList.get(position);
        //消息发送时间
        holder.tvSendMessageTime.setText(listBean.getSendTime());
        //消息内容
        holder.tvMessageContent.setText(listBean.getContent());
        //查看详情
        holder.btnCheckDetails.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class MessageViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_system_message)
        TextView tvSystemMessage;
        @BindView(R.id.tv_send_message_time)
        TextView tvSendMessageTime;
        @BindView(R.id.tv_message_content)
        TextView tvMessageContent;
        @BindView(R.id.view_line)
        View viewLine;
        @BindView(R.id.btn_check_details)
        TextView btnCheckDetails;
        public MessageViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
